home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / app / BaseWindow.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  11.6 KB  |  328 lines

  1. package com.extensibility.app;
  2.  
  3. import com.extensibility.print.Printer;
  4. import com.extensibility.rock.BaseMenu;
  5. import com.extensibility.rock.Platform;
  6. import com.extensibility.rock.RAction;
  7. import com.extensibility.xml.URI;
  8. import java.awt.Component;
  9. import java.awt.Dimension;
  10. import java.awt.Frame;
  11. import java.awt.Window;
  12. import java.awt.event.ActionEvent;
  13. import java.text.MessageFormat;
  14. import java.util.Date;
  15. import java.util.Enumeration;
  16. import java.util.EventObject;
  17. import javax.swing.AbstractAction;
  18. import javax.swing.AbstractButton;
  19. import javax.swing.JEditorPane;
  20. import javax.swing.JFrame;
  21. import javax.swing.JMenuBar;
  22. import javax.swing.JMenuItem;
  23. import javax.swing.SwingUtilities;
  24. import javax.swing.text.JTextComponent;
  25.  
  26. public abstract class BaseWindow extends JFrame {
  27.    BaseDocument document;
  28.    protected JMenuBar menubar;
  29.    protected BaseMenu muFile;
  30.    protected BaseMenu muEdit;
  31.    protected BaseMenu muWindows;
  32.    protected BaseMenu muHelp;
  33.    protected BaseMenu muNew;
  34.    int insertPos = 0;
  35.    int insertCount = 0;
  36.    boolean needSeparator = true;
  37.  
  38.    public BaseWindow(BaseDocument var1) {
  39.       this.document = var1;
  40.    }
  41.  
  42.    public void initialize(ApplicationPreferences var1) {
  43.       ((Component)this).setVisible(false);
  44.       ((Window)this).addWindowListener(Desktop.getWindowListener());
  45.       ((Frame)this).setIconImage(UI.getImage("ity.gif"));
  46.       ((JFrame)this).setDefaultCloseOperation(0);
  47.       this.setTitle();
  48.       ((JFrame)this).setJMenuBar(this.createMenuBar());
  49.    }
  50.  
  51.    public void performEdit(BaseEdit var1) {
  52.       this.getDocument().performEdit(var1);
  53.    }
  54.  
  55.    public static BaseWindow getWindow(Component var0) {
  56.       return (BaseWindow)SwingUtilities.windowForComponent(var0);
  57.    }
  58.  
  59.    public static BaseWindow getWindow(ActionEvent var0) {
  60.       Object var1 = ((EventObject)var0).getSource();
  61.       return var1 instanceof Component ? getWindow((Component)var1) : null;
  62.    }
  63.  
  64.    public void setSize(int var1, int var2) {
  65.       Dimension var3 = ((Component)this).getSize();
  66.       Dimension var4 = ((JFrame)this).getRootPane().getSize();
  67.       super.setSize(var1, var2);
  68.       Dimension var5 = ((Component)this).getSize();
  69.       int var6 = var5.width - var3.width;
  70.       int var7 = var5.height - var3.height;
  71.       Dimension var8 = ((JFrame)this).getRootPane().getSize();
  72.       if (var4.equals(var8) && !var3.equals(var5)) {
  73.          var8.width += var6;
  74.          var8.height += var7;
  75.          ((JFrame)this).getRootPane().setSize(var8);
  76.          ((JFrame)this).getRootPane().revalidate();
  77.       }
  78.    }
  79.  
  80.    protected JMenuBar createMenuBar() {
  81.       JMenuBar var1 = new JMenuBar();
  82.       this.muFile = (BaseMenu)var1.add(new BaseMenu(UI.getString("menu.file")));
  83.       this.muFile.setMnemonic(UI.getMnemonic("menu.file"));
  84.       this.muNew = new BaseMenu(UI.getString("file.item.new"));
  85.       String var2 = BaseApplication.getPreferences().getDefaultFileType();
  86.       this.updateNewSubMenuItems(UI.getFileTypeName(var2));
  87.       this.fillFileMenu();
  88.       this.muEdit = (BaseMenu)var1.add(new BaseMenu(UI.getString("menu.edit")));
  89.       this.muEdit.setMnemonic(UI.getMnemonic("menu.edit"));
  90.       this.fillEditMenu();
  91.       this.addOtherMenus(var1);
  92.       this.muWindows = (BaseMenu)var1.add(new BaseMenu(UI.getString("menu.window")));
  93.       this.muWindows.setMnemonic(UI.getMnemonic("menu.window"));
  94.       this.fillWindowsMenu();
  95.       this.muHelp = (BaseMenu)var1.add(new BaseMenu(UI.getString("menu.help")));
  96.       this.muHelp.setMnemonic(UI.getMnemonic("menu.help"));
  97.       this.fillHelpMenu();
  98.       return var1;
  99.    }
  100.  
  101.    protected void addOtherMenus(JMenuBar var1) {
  102.    }
  103.  
  104.    protected void fillEditMenu() {
  105.       this.createPreferencesAction().addToMenu(this.muEdit);
  106.    }
  107.  
  108.    protected void fillHelpMenu() {
  109.       this.createWelcomeAction().addToMenu(this.muHelp);
  110.       this.muHelp.addSeparator();
  111.       if (BaseApplication.isLaunchLimited()) {
  112.          this.createPurchaseAction().addToMenu(this.muHelp);
  113.          this.createRegisterAction().addToMenu(this.muHelp);
  114.          this.muHelp.addSeparator();
  115.       }
  116.  
  117.       this.createAboutAction().addToMenu(this.muHelp);
  118.    }
  119.  
  120.    protected void fillFileMenu() {
  121.       this.muFile.add(this.muNew);
  122.       this.createOpenAction().addToMenu(this.muFile);
  123.       this.createOpenURLAction().addToMenu(this.muFile);
  124.       this.createCloseAction().addToMenu(this.muFile);
  125.       this.createFileOpenSaveSeparator(this.muFile);
  126.       this.createSaveAction().addToMenu(this.muFile);
  127.       this.createSaveAsAction().addToMenu(this.muFile);
  128.       this.createSaveToURLAction().addToMenu(this.muFile);
  129.       this.createFileSavePrintSeparator(this.muFile);
  130.       this.createPrintSetupAction().addToMenu(this.muFile);
  131.       this.createPrintAction().addToMenu(this.muFile);
  132.       this.muFile.addSeparator();
  133.       this.createRecentMenuItems();
  134.       this.createExitAction().addToMenu(this.muFile);
  135.    }
  136.  
  137.    protected void createFileSavePrintSeparator(BaseMenu var1) {
  138.       var1.addSeparator();
  139.    }
  140.  
  141.    protected void createFileOpenSaveSeparator(BaseMenu var1) {
  142.       var1.addSeparator();
  143.    }
  144.  
  145.    public void fillWindowsMenu() {
  146.       if (this.muWindows != null) {
  147.          while(this.muWindows.getItemCount() > 0) {
  148.             this.muWindows.remove(0);
  149.          }
  150.  
  151.          this.createNewWindowAction().addToMenu(this.muWindows);
  152.          this.muWindows.addSeparator();
  153.          boolean var1 = true;
  154.          Enumeration var2 = Desktop.getDocuments();
  155.  
  156.          while(var2.hasMoreElements()) {
  157.             if (!var1) {
  158.                this.muWindows.addSeparator();
  159.             } else {
  160.                var1 = false;
  161.             }
  162.  
  163.             BaseDocument var3 = (BaseDocument)var2.nextElement();
  164.             Enumeration var4 = Desktop.getWindowsOfDocument(var3);
  165.  
  166.             while(var4.hasMoreElements()) {
  167.                BaseWindow var5 = (BaseWindow)var4.nextElement();
  168.                this.muWindows.add(new 1(var5, (BaseWindow)null, ((Frame)var5).getTitle()));
  169.             }
  170.          }
  171.  
  172.       }
  173.    }
  174.  
  175.    public BaseDocument getDocument() {
  176.       return this.document;
  177.    }
  178.  
  179.    final String getBaseTitle() {
  180.       String var1 = UI.getString("window.title.format");
  181.       String var2 = UI.getString(this.getClassName());
  182.       String[] var3 = new String[]{this.getDocument().getName(), var2};
  183.       return MessageFormat.format(var1, var3);
  184.    }
  185.  
  186.    public void setTitle() {
  187.       ((Frame)this).setTitle(this.getBaseTitle());
  188.    }
  189.  
  190.    public BaseWindow getSyblingWindow(Class var1) {
  191.       return Desktop.findWindow(new WindowMatchClass(this, var1));
  192.    }
  193.  
  194.    protected void createRecentMenuItems() {
  195.       this.insertPos = this.muFile.getItemCount();
  196.       this.updateRecentMenuItems();
  197.    }
  198.  
  199.    public void updateRecentMenuItems() {
  200.       for(int var1 = this.insertCount; var1 > 0; --var1) {
  201.          this.muFile.remove(this.insertPos);
  202.       }
  203.  
  204.       this.insertCount = 0;
  205.       int var3 = this.insertPos;
  206.       int var2 = 0;
  207.  
  208.       while(true) {
  209.          String var4 = BaseApplication.getPreference("RECENT.", var2 + 1);
  210.          if (var4 == null || var4.length() == 0) {
  211.             if (var2 > 0 && this.needSeparator) {
  212.                this.muFile.addSeparator();
  213.                this.needSeparator = false;
  214.             } else if (var2 == 0 && !this.needSeparator) {
  215.                this.muFile.remove(this.insertPos);
  216.                this.needSeparator = true;
  217.             }
  218.  
  219.             return;
  220.          }
  221.  
  222.          ++this.insertCount;
  223.          JMenuItem var5 = this.muFile.insert(this.createRecentAction(var2 + 1, new URI((URI)null, var4)), var3++);
  224.          ((AbstractButton)var5).setMnemonic((new Integer(var2 + 1)).toString().charAt(0));
  225.          ++var2;
  226.       }
  227.    }
  228.  
  229.    public void updateNewSubMenuItems(String var1) {
  230.       this.muNew.removeAll();
  231.       this.createNewAction(var1).addToMenu(this.muNew);
  232.    }
  233.  
  234.    protected RAction createNewAction(String var1) {
  235.       return new 2((BaseWindow)null, UI.getString("new.item.default", var1), 'N');
  236.    }
  237.  
  238.    protected BaseAction createOpenAction() {
  239.       return new 3((BaseWindow)null, "file.item.open", 'O');
  240.    }
  241.  
  242.    protected BaseAction createOpenURLAction() {
  243.       return new 4((BaseWindow)null, "file.item.open.url");
  244.    }
  245.  
  246.    protected BaseAction createSaveToURLAction() {
  247.       return new 5(this, "file.item.save.url");
  248.    }
  249.  
  250.    protected BaseAction createCloseAction() {
  251.       return new 6(this, "file.item.close", 'W');
  252.    }
  253.  
  254.    public BaseAction createNewWindowAction() {
  255.       return new 7(this, "item.newwindow");
  256.    }
  257.  
  258.    protected AbstractAction createRecentAction(int var1, URI var2) {
  259.       return new 8(var2, (BaseWindow)null, String.valueOf(String.valueOf(var1).concat(String.valueOf(" "))).concat(String.valueOf(var2.getShortName())));
  260.    }
  261.  
  262.    public void updateToolBarView() {
  263.    }
  264.  
  265.    protected RAction createSaveAction() {
  266.       return new 9(this, "file.item.save", 'S');
  267.    }
  268.  
  269.    protected RAction createSaveAsAction() {
  270.       return new 10(this, "file.item.save.as");
  271.    }
  272.  
  273.    protected RAction createPrintSetupAction() {
  274.       return new 11(this, "file.item.print.setup");
  275.    }
  276.  
  277.    protected RAction createPrintAction() {
  278.       return new 12(this, "file.item.print", 'P');
  279.    }
  280.  
  281.    protected RAction createExitAction() {
  282.       return (RAction)(Platform.isMac() ? new 13((BaseWindow)null, "file.item.quit", 'Q') : new 14((BaseWindow)null, "file.item.exit"));
  283.    }
  284.  
  285.    protected RAction createPurchaseAction() {
  286.       return new 15(this, "help.item.purchase");
  287.    }
  288.  
  289.    protected RAction createRegisterAction() {
  290.       return new 16((BaseWindow)null, "help.item.register");
  291.    }
  292.  
  293.    protected RAction createWelcomeAction() {
  294.       return new 17((BaseWindow)null, "help.item.welcome");
  295.    }
  296.  
  297.    public static RAction createHelpAction(String var0) {
  298.       return new 18(var0, var0);
  299.    }
  300.  
  301.    protected RAction createAboutAction() {
  302.       return new 19((BaseWindow)null, "help.item.about");
  303.    }
  304.  
  305.    protected RAction createPreferencesAction() {
  306.       return new 20(this, "edit.item.preferences");
  307.    }
  308.  
  309.    public abstract String getClassName();
  310.  
  311.    protected abstract String getText();
  312.  
  313.    public void printWindow(ActionEvent var1) {
  314.       try {
  315.          Printer var2 = new Printer();
  316.          String var3 = this.getDocument().getName();
  317.          var2.setHeader(String.valueOf(UI.getAppName()).concat(String.valueOf(" ")), "", UI.getString("print.file", var3));
  318.          var2.setFooter((new Date()).toString(), "", UI.getString("print.page"));
  319.          JEditorPane var4 = new JEditorPane("text/plain", this.getText());
  320.          ((JTextComponent)var4).setEditable(false);
  321.          var2.print(var3, var4, false);
  322.       } catch (Exception var5) {
  323.          DialogFactory.showException(this, 124, var5);
  324.       }
  325.  
  326.    }
  327. }
  328.